<?php
require_once '../inc/configuration.php';
require_once '../inc/connexion_db.php';
require_once '../inc/fonctions_sql.php';

$message_action = "";

$action = isset($_POST["action"]) ? $action = $_POST["action"] : "";
if(isset($_GET["id"])) {
    $id = $_GET["id"];
}
else if(isset($_POST["id"])) {
    $id = $_POST["id"];
}
else {
    $id = "";
}

if($action==1) {
    
    $tab_name_form = array(
        "id_contact",
        "rdv_date",
        "heure",
        "type_rdv",
        "objet",
        "observations",
    );
    
    $message_action = modifier_donnees("rendez_vous", $id, $tab_name_form);
}
$sql = "SELECT * FROM rendez_vous WHERE id=".$id;
$req = mysqli_query($connexion_bd, $sql);
$data = mysqli_fetch_array($req);
?>

<!DOCTYPE html>

<html>
    <head>
        <meta charset="ISO-8859-1">
        <title></title>
         
        <?php require_once "../inc/css_js_bootstrap/css_js_bootstrap.php"; ?>
        
        <style>
            .table {
                width: 500px;
            }
            
            th {
                width: 35%;
                text-align: right;
            }
            textarea.form-control {
                /*background-color: #ccc;*/
                height: 150px;
            }
            
        </style>
    </head>
    <body>
        
        <?php require_once '../inc/menus/menu_principal.php'; ?>
        
        <h1>MODIFIER UN RENDEZ VOUS</h1>
        <?php if(!empty($message_action)) { ?>
            <div id="message_action" class="alert <?php echo $message_action["css_class"]; ?>"><?php echo $message_action["texte"]; ?></div>
        <?php } ?>
        <form name="form_ajouter" id="form_ajouter" method="post"enctype="multipart/form-data">
        <div>
            <table class="table table-bordered">
                <tr>
                    <th>Contact</th>
                    <td> 
              <?php
//             $sql = "SELECT id, raison_sociale FROM entreprises ";
//             $req = mysqli_query($connexion_bd, $sql);
        
              ?>               
               <select name="id_entreprise" id="id_entreprise" class="form-control">
                           <?php
                
                $sql_rdv = "SELECT contacts.id AS id, contacts.nom AS nom, contacts.prenom AS prenom, entreprises.raison_sociale AS r_s FROM contacts, entreprises WHERE contacts.id_entreprise=entreprises.id";
                $req_rdv = mysqli_query($connexion_bd, $sql_rdv);
                while($data_rdv = mysqli_fetch_assoc($req_rdv)) {
              
            ?>
                    <option value="<?php echo $data_rdv["id"]; ?>" ><?php echo $data_rdv["nom"]; ?><?php echo $data_rdv["prenom"]; ?> => <?php echo $data_rdv["r_s"]; ?></option>
            <?php
                }
           
             $sql1 = "SELECT rdv_date,heure,type_rdv,objet,observations FROM rendez_vous WHERE id=".$_GET["id"];
             $req1 = mysqli_query($connexion_bd, $sql1);
             $data= mysqli_fetch_assoc($req1);
            ?>
           
                    </select>
                    </td>
                </tr>
                <tr>
                    <th>Date</th>
                    <td>
                        <input type="date" name="rdv_date" id="rdv_date" class="form-control champ_textarea" value="<?php echo $data["rdv_date"]; ?>">
                        
                    </td>
                </tr>
                <tr>
                    <th>Heure</th>
                    <td><input type="time" id="heure"  class="form-control" value="<?php echo $data["heure"]; ?>"/><br /></td>
                </tr>
                <tr>
                    <th>type du rendez vous</th>
                    <td><input type="type_rdv" name="type_rdv" id="type_rdv" class="form-control" value="<?php echo $data["type_rdv"]; ?>"></td>
                </tr>
                <tr>
                    <th>Objet</th>
                    <td><input type="objet" name="objet" id="objet" class="form-control" value="<?php echo $data["objet"]; ?>"></td>
                </tr>
                <tr>
                    <th>Observations</th>
                    <td><textarea name="observations" id="observations" class="form-control champ_textarea" value="<?php echo $data["observations"]; ?>"></textarea></td>
                </tr>
                <tr>
                    <th></th>
                    <td><button type="submit" name="action" class="btn btn-success" value="1"><span class="glyphicon glyphicon-ok"></span> Modifier</button></td>
                </tr>
            </table>
        </div>
        </form>
       
    </body>
</html>